<template>
  <div class="ma-content-block lg:flex justify-between p-4">
    <!-- CRUD 组件 -->
    <ma-crud :options="options" :columns="columns" ref="crudRef">
    </ma-crud>
  </div>
</template>
<script setup>
import { ref, reactive } from 'vue'
import realname from '@/api/backend/realname.js'
import { Message } from '@arco-design/web-vue'
import tool from '@/utils/tool.js'
import * as common from '@/utils/common.js'

const crudRef = ref()


const numberOperation = (newValue, id, numberName) => {
  realname.numberOperation({ id, numberName, numberValue: newValue }).then( res => {
    res.success && Message.success(res.message)
  }).catch( e => { console.log(e) } )
}

const switchStatus = (statusValue, id, statusName) => {
  realname.changeStatus({ id, statusName, statusValue }).then( res => {
    res.success && Message.success(res.message)
  }).catch( e => { console.log(e) } )
}


const options = reactive({
  id: 'user_realname',
  rowSelection: {
    showCheckedAll: true
  },
  pk: 'id',
  operationColumn: true,
  operationColumnWidth: 160,
  formOption: {
    viewType: 'drawer',
    width: 600
  },
  api: realname.getList,
  recycleApi: realname.getRecycleList,
  add: {
    show: true,
    api: realname.save,
    auth: ['realname:save']
  },
  edit: {
    show: true,
    api: realname.update,
    auth: ['realname:update']
  },
  delete: {
    show: true,
    api: realname.deletes,
    auth: ['realname:delete'],
    realApi: realname.realDeletes,
    realAuth: ['realname:realDeletes']
  },
  recovery: {
    show: true,
    api: realname.recoverys,
    auth: ['realname:recovery']
  }
})

const columns = reactive([
  {
    title: "ID",
    dataIndex: "id",
    formType: "input",
    addDisplay: false,
    editDisplay: false
  },
  {
    title: "创建时间",
    dataIndex: "created_at",
    formType: "date",
    addDisplay: false,
    editDisplay: false,
    showTime: true
  },
  {
    title: "更新时间",
    dataIndex: "updated_at",
    formType: "date",
    addDisplay: false,
    editDisplay: false,
    showTime: true
  },
  {
    title: "删除时间",
    dataIndex: "deleted_at",
    formType: "date",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    showTime: true
  },
  {
    title: "0未认证1通过2拒绝",
    dataIndex: "status",
    formType: "select",
    multiple: false,
    dict: {
      data: [
        {
          label: "未认证",
          value: "0"
        },
        {
          label: "通过",
          value: "1"
        },
        {
          label: "拒绝",
          value: "2"
        }
      ],
      translation: true
    }
  },
  {
    title: "国家数字代码",
    dataIndex: "code",
    formType: "select"
  },
  {
    title: "身份证号码",
    dataIndex: "id_no",
    formType: "input",
    search: true
  }
])
</script>
<script> export default { name: 'realname' } </script>